package com.example.test.entity.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author decent
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PageResult implements Serializable {

    private static final long serialVersionUID = -1369948390563179412L;

    /**
     * 总数
     */
    private Long total;

    /**
     * 当前页数量
     */
    private Integer size;

    /**
     * 总页数
     */
    private Integer pages;

    /**
     * 数据集
     */
    private List<?> rows;

    /**
     * 每页数量
     */
    private Integer pageSize;

    /**
     * 当前页
     */
    private Integer pageNumber;

    public PageResult() {
    }

    public PageResult(Long total, List<?> rows) {
        this.total = total;
        this.rows = rows;
    }

    public PageResult(Long total, Integer size, Integer pages, List<?> rows, Integer pageSize, Integer pageNumber) {
        this.total = total;
        this.size = size;
        this.pages = pages;
        this.rows = rows;
        this.pageSize = pageSize;
        this.pageNumber = pageNumber;
    }

    public PageResult(PageInfo<?> pageInfo) {
        this.total = pageInfo.getTotal();
        this.size = pageInfo.getSize();
        this.pages = pageInfo.getPages();
        this.rows = pageInfo.getList();
        this.pageSize = pageInfo.getPageSize();
        this.pageNumber = pageInfo.getPageNum();
    }
}
